<!doctype html>
<html class="no-js fixed-layout">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>首页</title>
  <meta name="description" content="index">
  <meta name="keywords" content="index">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="icon" type="image/png" href="/static/assets/i/favicon.png">
  <link rel="apple-touch-icon-precomposed" href="/static/assets/i/app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-title" content="Amaze UI" />
  <link rel="stylesheet" href="/static/assets/css/amazeui.min.css"/>
  <link rel="stylesheet" href="/static/assets/css/admin.css">
</head>
<body>



  <div class="admin-content">

    <div class="admin-content-body">

      <div class="am-g">


 
        <div class="am-u-sm-12 am-u-md-12 ">
          <!--中间侧块 注意下面是form表-->
          <br>
          <table id="grid" class="am-table am-table-striped am-table-hover table-main am-table-compact am-text-nowrap" width="100%">
            <thead>
              <tr>
                <th class="table-title"> <input type="checkbox" id="checkAll"  onclick="check_all()" > 全选</th>
                <th class="table-title">部件名称</th>
                <th class="table-title">编号</th>
                <th class="table-title">注释</th>
              </tr>
            </thead>
            <tbody>
            </tbody>
          </table>

          
        </div>
        <div class="am-u-sm-12 am-u-md-6">
          <div class="am-btn-toolbar">
            <div class="am-btn-group am-btn-group-xs">
            <div class="am-margin">
              <button type="button" class="am-btn am-btn-primary am-btn-xs" onclick="save()">保存</button>
            </div>

            </div>
          </div>
        </div>

      </div>
    </div>

  </div>

<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="/static/assets/js/jquery.min.js"></script>
<!--<![endif]-->
<script src="/static/assets/js/amazeui.min.js"></script>
<script src="/static/assets/js/amazeui.tree.js"></script>
<script src="/static/assets/datatables/amazeui.datatables.min.js"></script>
<script src="/static/assets/dialog/amazeui.dialog.min.js"></script>
<link rel="stylesheet" type="text/css" href="/static/assets/css/amazeui.tree.css" />
<script type="text/javascript" src="/static/assets/js/layer.js"></script>
<script src="/static/assets/js/app.js"></script>
<script type="text/javascript">

var bridge_id = {{ bridge_id|safe }}
var parts_code = {{ parts_code|safe }}
var unit_component_id = {{ unit_component_id|safe }}
var unit_id = {{ unit_id|safe }}
$(document).ready(function(){
  var t = $('#grid').DataTable({
  //配置DataTables默认参数



    bInfo: true,//页脚信息
    responsive: true,
    searching: true,
    lengthChange: false,
    paging: true,
    bStateSave: false, //保存页面状态
    aoColumnDefs: [{
          "bSortable": false,
          "aTargets": [0]
        }],   //首行不排序
    aLengthMenu: [[-1],["所有"]],
    ajax: {

      url: "/QLXJ_QLLB_PFDY_SelectComponent_data/?bridge_id="+bridge_id+"&unit_id="+unit_id+"&parts_code="+parts_code+"&unit_component_id="+unit_component_id+""
    },


    
    //每页显示五条数据
    //pageLength: 'all',
    columns: [
    /*
      {  
        data : null,  
        bSortable : false,  
        targets : 0,  
        //width : "30px",  
        render : function(data, type, row, meta) {  
          // 显示行号  
          var startIndex = meta.settings._iDisplayStart;  
          return startIndex + meta.row + 1;  
        }  
      },
    */
      {
            data: null,
            bSortable: false,
            targets: 0,
            //width : "30px",  
            render: function(data, type, row, meta) {
              if(row.flag == 1){
                return '<input type="checkbox" name="Checkbox_number"  class="checkchild"  value=' + row.bridge_member_id + ' checked>';
              }else{
                return '<input type="checkbox" name="Checkbox_number" class="checkchild"  value=' + row.bridge_member_id + '>';
              }
              
            }
      },
      {
        "data": "parts_name"
      },
      {
        "data": "member_name"
      },

      {
        "data": "notes"
      }
    ],
    
    
    "columnDefs": [
      // "visible": false,
      //"targets": 0



      {
        type: 'chinese-string',
        targets: 1
      } //中文排序
      
    ],
    

  });


        $('#grid tbody').on( 'click', 'tr', function () {
          // $(this).children('td').eq(0).find("input:checkbox").attr("checked");
          // console.log($(this).children('td').eq(0).find("input:checkbox"));
          // console.log($(this).children('td').eq(0));
          var check = $(this).find(".checkchild").prop("checked");
         if(check && check==true){
             $(this).find('.checkchild').prop("checked",false);
             $("#checkAll").prop("checked",false);
        }else{
            $(this).find('.checkchild').prop("checked",true);
        }





        });

        $(document).on("click",".checkchild",function(){
        var check = $(this).prop("checked");
        if(check && check==true){
            $(this).prop("checked",false);
        }else{
            $(this).prop("checked",true);
        }

    });





})



function check_all() {
        if($("#checkAll").prop('checked') == true) {
          $("input[name^=Checkbox_number]").each(function() {
            $(this).prop('checked', true);
          })
        } else {
          $("input[name^=Checkbox_number]").each(function() {
            $(this).prop('checked', false);
          })
        }
      }

function save() {
        var bridge_member_id = "";
        $("input[name^=Checkbox_number]").each(function() {
          if ($(this).prop('checked')==true) {
            b = $(this).val();
            if(bridge_member_id == ""){
              bridge_member_id =  b;
            }else{
              bridge_member_id = bridge_member_id + '|' + b;
            }
            
          }
        });



            $.ajax({
              "url": "/QLXJ_QLLB_PFDY_SelectComponent_save/?bridge_id="+bridge_id+"&unit_id="+unit_id+"&parts_code="+parts_code+"&unit_component_id="+unit_component_id+"&bridge_member_id="+bridge_member_id+"",
              "datatype": "json",
              "type": "get",
              "async": "false"
            }).success(function(data) {
              if(data.status == 1) {
                message_layer(data.message)
                var index = parent.layer.getFrameIndex(window.name);
                parent.location.reload();
                parent.layer.close(index);
                // console.log(data.data)
              } else {
                AlertMSG(data.message)
              }
            }).error(function(data) {
              AlertMSG("保存失败！")
            });
 

      }

// message_layer(data.message)
function message_layer(message){
    layer.msg(message, {
    time: 2000 //2秒关闭（如果不配置，默认是3秒）
  }); 
}

var AlertMSG=function(msg){
    AMUI.dialog.alert({ title: '错误提示', content: msg, onConfirm: function() { console.log('close'); } });
}
</script>
</body>

</html>